package com.zxl.grocerymicroservicewechatmeal.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.zxl.grocerymicroservicewechatmeal.dataobject.OrderDetail;
import com.zxl.grocerymicroservicewechatmeal.enums.OrderStatusEnum;
import com.zxl.grocerymicroservicewechatmeal.enums.PayStatusEnum;
import com.zxl.grocerymicroservicewechatmeal.utils.EnumUtil;
import com.zxl.grocerymicroservicewechatmeal.utils.serializer.Date2LongSerializer;
import lombok.Data;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author: zxl
 * @Description: 订单 （在各个层中传输对象）
 * @Date: Created in 9:17 2017/11/16
 * @Modified By:
 */
@Data
//@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)//不返回为null的字段(已经废弃了)
//@JsonInclude(JsonInclude.Include.NON_NULL)//不返回为null的字段（最新的用法）
public class OrderDTO {

    /** 订单id. */
    private String orderId;

    /** 买家名字. */
    private String buyerName;

    /** 买家手机号. */
    private String buyerPhone;

    /** 买家地址. */
    private String buyerAddress;

    /** 买家微信Openid. */
    private String buyerOpenid;

    /** 订单总金额. */
    private BigDecimal orderAmount;

    /** 订单状态, 默认为0新下单. */
    private Integer orderStatus;

    /** 支付状态, 默认为0未支付. */
    private Integer payStatus;

    /** 创建时间. */
    @JsonSerialize(using = Date2LongSerializer.class)//返回的单位由毫秒转化为秒
    private Date createTime;

    /** 更新时间. */
    @JsonSerialize(using = Date2LongSerializer.class)
    private Date updateTime;

    List<OrderDetail> orderDetailList;
   // List<OrderDetail> orderDetailList = new ArrayList<>();//如果该字段是必须返回字段、并且返回结果不能是null，当该字段为null时返回空列表

    @JsonIgnore//对象转化成为json格式时会忽略掉该字段
    public OrderStatusEnum getOrderStatusEnum() {
        return EnumUtil.getByCode(orderStatus, OrderStatusEnum.class);
    }

    @JsonIgnore
    public PayStatusEnum getPayStatusEnum() {
        return EnumUtil.getByCode(payStatus, PayStatusEnum.class);
    }
}

